<?php

class BuildingController extends Controller
{
	public function actionIndex()
	{
		$this->render('index');
	}

        public function actionUpdate($name, $id = -1) {
            $model;
            if($id > 0) {
                $model = Building::model()->findByPk($id);
                if($model === null) {
                    $this->renderPartial("..\admin\jsonError", array("errId" => 3, "errEx" => "\"Requested record doesn't exists!\""));
                    Yii::app()->end();
                }
            } else {
                $model = new Building();
            }

            //save
            $model->name = $name;
            try {
                if($model->save()) {
                    //Send OK JSON
                    $this->renderPartial("..\admin\jsonOK");
                } else {
                    //Send error JSON, save failed
                    $this->renderPartial("..\admin\jsonError", array("errId" => 4, "errEx" => "\"Make sure the building name has not taken!\""));
                }
            } catch(CDbException $ex) {
                    //Send error JSON, save failed
                    $this->renderPartial("..\admin\jsonError", array("errId" => 4, "errEx" => "\"Make sure the building name has not taken!\""));
            }
        }

        public function actionDelete($id) {
            Building::model()->deleteByPk($id);
            $this->renderPartial("..\admin\jsonOK");
        }

        public function actionGetInfoAll() {
            $this->renderPartial("infoAll", array("models" => Building::model()->findAll()));
        }

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}